﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;


namespace PRE
{
    public partial class FrmMain : RibbonForm
    {
        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";
        private const string STR_Nguoidung = "";
        public static UTL.Session _sss = new UTL.Session();

        public FrmMain()
        {
            InitializeComponent();
            InitSkinGallery();
            //InitGrid();

        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }
        

        private void FrmMain_Load(object sender, EventArgs e)
        {
            bbiDangnhap_ItemClick(sender, null);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            bsiThoigian.Caption = "Thời gian: " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
        }
        // ----------------------------- Các Items chức năng -------------------------

        #region Hệ thống

        #region Chức năng

        private void bbiDangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (bbiDangnhap.Caption == STR_LOGOUT)
            {
                bsiUser.Caption = STR_Nguoidung;
                _sss.Login = false;
                bbiDangnhap.Caption = STR_LOGIN;
                bbiDongtatca_ItemClick(sender, e);
            }

            Login.FrmLogin x = new Login.FrmLogin();
            x.ShowDialog();

            if (_sss.Login)
            {
                bsiUser.Caption = "Xin chào: " + _sss.Name;
                bbiDangnhap.Caption = STR_LOGOUT;
                rpQuanly.Visible = true;
                rpThongke.Visible = true;
                rpgNguoidung.Visible = true;
                bbiGiaitri.Visibility = BarItemVisibility.Always;
            }
            else
            {
                rpQuanly.Visible = false;
                rpThongke.Visible = false;
                rpgNguoidung.Visible = false;
                bbiGiaitri.Visibility = BarItemVisibility.Never;
            }
        }

        private void bbiGiaitri_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Giaitri.FrmMedia) return;
            var frm = new Giaitri.FrmMedia() { MdiParent = this };

            frm.Show();
        }
        #endregion

        #region Người dùng

        private void bbiThanhvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmThanhvien) return;
            var frm = new Catalog.FrmThanhvien() { MdiParent = this };

            frm.Show();
        }

        private void bbiVaitro_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmVaitro) return;
            var frm = new Catalog.FrmVaitro() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Thoát

        private void bbiDongtatca_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var frm in MdiChildren) frm.Close();
        }

        private void bbiThoat_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát khỏi chương trình hay không ", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                this.Close();
            }
        }

        #endregion

        #endregion

        #region Quản lý

        #region Ghi danh

          private void bbiDangky_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Register.FrmDangky) return;
            var frm = new Register.FrmDangky() { MdiParent = this };

            frm.Show();
        }

          private void bbiNhapdiem_ItemClick(object sender, ItemClickEventArgs e)
          {

              foreach (var x in MdiChildren) if (x is Catalog.FrmNhapdiem) return;
              var frm = new Catalog.FrmNhapdiem() { MdiParent = this };

              frm.Show();
          }
        #endregion

        #region Thông tin

        private void bbiHocvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmHocvien) return;
            var frm = new Catalog.FrmHocvien() { MdiParent = this };

            frm.Show();
        }

        private void bbiGiaovien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmGiaovien) return;
            var frm = new Catalog.FrmGiaovien() { MdiParent = this };

            frm.Show();
        }

        private void bbiPhonghoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmPhonghoc) return;
            var frm = new Catalog.FrmPhonghoc() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Giảng dạy

        private void bbiCahoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmTKBieu) return;
            var frm = new Catalog.FrmTKBieu() { MdiParent = this };

            frm.Show();
        }

        private void bbiDaylop_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmDaylop) return;
            var frm = new Catalog.FrmDaylop() { MdiParent = this };

            frm.Show();
        }

        #endregion

        #region Cập nhật

        private void bbiKhoahoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmKhoahoc) return;
            var frm = new Catalog.FrmKhoahoc() { MdiParent = this };

            frm.Show();
        }

        private void bbiLophoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmLophoc) return;
            var frm = new Catalog.FrmLophoc() { MdiParent = this };

            frm.Show();
        }

        private void bbiLoaichungchi_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmLoaichungchi) return;
            var frm = new Catalog.FrmLoaichungchi() { MdiParent = this };

            frm.Show();
        }

        #endregion
        
        #region Chi tiết

        private void bbiPhieuthu_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmXembienlai) return;
            var frm = new Catalog.FrmXembienlai() { MdiParent = this };

            frm.Show();
        }
           private void bbiTKB_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Catalog.FrmTKB) return;
            var frm = new Catalog.FrmTKB() { MdiParent = this };

            frm.Show();
        }

           private void bbiXemdiem_ItemClick(object sender, ItemClickEventArgs e)
           {
               foreach (var x in MdiChildren) if (x is Catalog.FrmXemdiem) return;
               var frm = new Catalog.FrmXemdiem() { MdiParent = this };

               frm.Show();
           }


        #endregion
             
       #endregion
         
        #region Thống kê
       
        #region Học viên

           private void bbiSLHV_ItemClick(object sender, ItemClickEventArgs e)
           {
               foreach (var x in MdiChildren) if (x is Report_Catalog.Frm_Thongke_Hocvien) return;
               var frm = new Report_Catalog.Frm_Thongke_Hocvien() { MdiParent = this };

               frm.Show();
           }

            private void bbiDSDangky_ItemClick(object sender, ItemClickEventArgs e)
            {
                foreach (var x in MdiChildren) if (x is Report_Catalog.FrmThongke_hv_theolop) return;
                var frm = new Report_Catalog.FrmThongke_hv_theolop() { MdiParent = this };

                frm.Show();
            }

            private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
            {
                foreach (var x in MdiChildren) if (x is Register.FrmDSDangky) return;
                var frm = new Register.FrmDSDangky() { MdiParent = this };

                frm.Show();
            }

        #endregion

        #region Doanh thu

            private void bbiDoanhthu_khoa_ItemClick(object sender, ItemClickEventArgs e)
            {

                foreach (var x in MdiChildren) if (x is Report_Catalog.FrmThongke_Doanhthu_Theolop) return;
                var frm = new Report_Catalog.FrmThongke_Doanhthu_Theolop() { MdiParent = this };

                frm.Show();
            }

        #endregion
      
        #endregion

        #region Help

            private void bbiGioithieu_ItemClick(object sender, ItemClickEventArgs e)
            {
                Help.FrmGioithieu frm = new Help.FrmGioithieu();
                frm.ShowDialog();
            }
            private void bbiHuongdan_ItemClick(object sender, ItemClickEventArgs e)
            {
                System.Diagnostics.Process.Start("..\\..\\Help.chm");
            }
        #endregion

       // ----------------------------- Các Items chức năng -------------------------
    }
}